package com.hhq.internationalization.util;

import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

/**
 * <p>Description: some description </p>
 *
 * @author : xiaodong.yang
 * @date : 2024/5/6 11:35
 */
public class MessageUtils {
    private MessageUtils() {
        throw new IllegalStateException("Utility class");
    }

    private static final MessageSource messageSource = SpringUtil.getBean(MessageSource.class);

    public static String getLocale(String msg) {
        try {
            return messageSource.getMessage(msg, null, LocaleContextHolder.getLocale());
        } catch (Exception e) {
            return msg;
        }
    }
}
